package com.compty.paint.manager;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.compty.core.hibernate.HibernateEntityDao;
import com.compty.security.domain.UserState;

/**
 * @Todo:用户(管理员及会员)状态 Manager
 * @author: 朱庆辉
 * @CreateTime:2012-4-12 上午10:53:49
 */
public class UserStateManager extends HibernateEntityDao<UserState>{
	
	private static Map<String,UserState> userStateMap = new HashMap<String, UserState>();
	
	private static List<UserState> userStateList = null;
	
	public UserState findUniqueBy(String fieldName, Object value){
		
		if("english_name".equals(fieldName)){
			
			if(userStateMap.size() == 0){
				List<UserState>  list = getAll();
				for (UserState userState : list) {
					String key = userState.getEnglish_name();
					userStateMap.put(key, userState);
				}
			}
			
			return userStateMap.get(value);
		}
		else{
			return super.findUniqueBy(fieldName, value);
		}
	}
	
	public List<UserState> getAll(){
		if(userStateList == null){
			return super.getAll();
		}else{
			return userStateList;
		}
	}

}
